﻿set(BUILD_TESTING OFF CACHE INTERNAL "")
set(ENABLE_PYTHON OFF CACHE INTERNAL "")

include(FetchContent)

set(winpatch git apply --ignore-whitespace --reject ${PROJECT_SOURCE_DIR}/third_package/libtuntap-win.patch)

FetchContent_Declare(
    libtuntap
    DOWNLOAD_EXTRACT_TIMESTAMP YES
    URL ${PROJECT_SOURCE_DIR}/third_package/libtuntap.tar
    URL_HASH MD5=a045bdf3199e3f185c7917f25eeeed5c
    PATCH_COMMAND ${winpatch}
    UPDATE_DISCONNECTED 1
)

FetchContent_GetProperties(libtuntap)

if(NOT libtuntap_POPULATED)
    FetchContent_Populate(libtuntap)
    add_subdirectory(${libtuntap_SOURCE_DIR} ${libtuntap_BINARY_DIR} EXCLUDE_FROM_ALL)
endif()

add_executable(tuntap_bb)
target_sources(tuntap_bb PRIVATE test_bb_tun.cpp)

target_link_libraries(tuntap_bb PRIVATE ar8030_client)
target_link_libraries(tuntap_bb PRIVATE tuntap++ com)
target_include_directories(tuntap_bb PRIVATE ./)

INSTALL(TARGETS tuntap_bb
    RUNTIME DESTINATION dev_helper
)

if(WIN32)
    INSTALL(FILES NordVPNTapSetup.exe
        DESTINATION driver
    )
endif()
